﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using App.Data;
using App.Core.Extensions;

public partial class Pages_Public_CompanyList : BasePage
{
    protected int _BusinessTypeID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        BindPageInfo();
        if (!IsPostBack)
        {
            BindCustomerList();
        }
    }
    protected void BindPageInfo()
    {
        Page.Title = WebUtil.GetPageTitle(h4Heading.InnerHtml);
        _BusinessTypeID = WebUtil.GetQueryStringInInt(AppConstants.QueryString.ID);
        this.Master.ShowServiceProviderMenu = true;
    }
    protected void BindCustomerList()
    {
        BtcHousingEntities context = new BtcHousingEntities();
        BusinessType category = context.BusinessTypes.FirstOrDefault(C => C.ID == _BusinessTypeID);
        if (category != null)
            h4Heading.InnerHtml = String.Format("Company List of {0}", category.ShortName);

        var companies = from P in context.Customers where P.BusinessTypeID == _BusinessTypeID && P.IsDeleted == false && P.IsApproved == true  select P;
        if (companies == null || companies.Count() == 0)
        {
            ucCustomerList.DataSource = null;
            WebUtil.ShowMessageBox(divMessage, String.Format("No Company found for {0}", category == null ? "this category." : category.ShortName), true);
        }
        else
            ucCustomerList.DataSource = companies.ToList();
        ucCustomerList.DataBind();
    }
}